import wx
import os
import sys
ID_ABOUT=101
ID_DLDPCK=102
ID_LOAD=103
ID_NEW=104
ID_EDIT=105
ID_SAVE=106
ID_ULDPCK=107
ID_PREF=108
ID_EXIT=110
ID_ANSWER=120
ID_CLEAR=121
name='QuizPackBETA'
class QuizPackGUI(wx.Frame):
    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,wx.ID_ANY,title, size=(640,480))
        self.CreateStatusBar()
        #File menu
        filemenu=wx.Menu()
        filemenu.Append(ID_DLDPCK,'[&Download a pack]','Download a quizpack from the Internet, once available.')
        filemenu.Append(ID_LOAD,'&Load pack from file','Specify a quizpack file to load.')
        filemenu.AppendSeparator()
        filemenu.Append(ID_EXIT,'E&xit','Leave '+name+'.')
        #Edit menu
        editmenu=wx.Menu()
        editmenu.Append(ID_NEW,'&Create new pack','Design a new quizpack from scratch.')
        editmenu.Append(ID_EDIT,'&Edit pack','Open an existing pack for modification.')
        editmenu.Append(ID_SAVE,'&Save pack','Save changes to a pack.')
        editmenu.Append(ID_ULDPCK,'[&Upload pack]','Upload a pack to the Internet, once available.')
        editmenu.AppendSeparator()
        editmenu.Append(ID_PREF, 'Prefere&nces...','Change various settings.')
        #Help menu
        helpmenu=wx.Menu()
        helpmenu.Append(ID_ABOUT,'&About','About QuizPackBETA.')
        #Menu bar
        menuBar = wx.MenuBar()
        menuBar.Append(filemenu,"&File")
        menuBar.Append(editmenu,"&Edit")
        menuBar.Append(helpmenu,"&Help")
        self.SetMenuBar(menuBar)
        self.Show(True)

        #Actual UI
        #Question display box (NOT FUNCTIONAL)
        #self.questiondisplay = wx.TextCtrl(self, 0, "", style=wx.TE_READONLY)
        self.panel = wx.Panel(self, -1)

        self.textbox1 = wx.TextCtrl(self.panel, -1, '', (17,48), size=(595, 20), style=wx.TE_READONLY)
        self.textbox1.SetBackgroundColour(wx.Colour(255, 255, 255))
        self.textbox1.SetFont(wx.Font(8.25, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, 'Microsoft Sans Serif'))
        self.textbox1.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))

        self.label1 = wx.StaticText(self.panel, -1, 'Question:', (16,24), (159, 18))
        self.label1.SetFont(wx.Font(8.25, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, 'Microsoft Sans Serif'))
        self.label1.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))

        self.label2 = wx.StaticText(self.panel, -1, 'Your Answer:', (16,96), (112, 17))
        self.label2.SetFont(wx.Font(8.25, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, 'Microsoft Sans Serif'))
        self.label2.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))

        self.textbox2 = wx.TextCtrl(self.panel, -1, 'textbox', (16,120), size=(470, 20))
        self.textbox2.SetBackgroundColour(wx.Colour(255, 255, 255))
        self.textbox2.SetFont(wx.Font(8.25, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, 'Microsoft Sans Serif'))
        self.textbox2.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))

        self.button1 = wx.Button(self.panel, -1, 'Answer', (488,120), (56, 17))
        self.button1.SetFont(wx.Font(8.25, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, 'Microsoft Sans Serif'))
        self.button1.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
        self.button1.SetId(ID_ANSWER)
        
        self.button2 = wx.Button(self.panel, -1, 'Clear', (552,120), (56, 17))
        self.button2.SetFont(wx.Font(8.25, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, 'Microsoft Sans Serif'))
        self.button2.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
	self.button2.SetId(ID_CLEAR)
        #Event Handling
        wx.EVT_MENU(self, ID_ABOUT, self.OnAbout)
        wx.EVT_MENU(self, ID_DLDPCK, self.OnDownload)   
        wx.EVT_MENU(self, ID_EXIT, self.OnExit)
        wx.EVT_MENU(self, ID_LOAD, self.OnOpen)
        wx.EVT_MENU(self, ID_SAVE, self.OnSave)
        wx.EVT_MENU(self, ID_NEW, self.OnNew)
        wx.EVT_MENU(self, ID_EDIT, self.OnEdit)
        wx.EVT_MENU(self, ID_DLDPCK, self.OnUpload)
        wx.EVT_MENU(self, ID_PREF, self.OnPrefs)
        wx.EVT_MENU(self, ID_ULDPCK, self.OnUpload)
	wx.EVT_BUTTON(self, ID_ANSWER, self.OnAnswer)
	wx.EVT_BUTTON(self, ID_CLEAR, self.OnClear)
    def OnNotImplemented(self, e):
        d= wx.MessageDialog( self, "NOT IMPLEMENTED, YET.","QuizPackBETA", wx.OK)
        d.ShowModal()
        d.Destroy()
    def OnAbout(self, e):
        d= wx.MessageDialog( self, name+"\n"
        "A studying tool for you.","About "+name, wx.OK)
        d.ShowModal()
        d.Destroy()
    def OnClear(self, e):
	print 'Clearing the answer box'
	self.textbox2.Clear()
    def OnDownload(self, e):
        OnNotImplemented(e)
    def OnExit(self, e):
        self.Close(True)
        quizpacklib.leave()
    def OnAnswer(self, e):
        print 'Answered'
        print self.textbox2.GetLineText(0)
        print 'Clearing question box'
        self.textbox1.Clear()
        print 'Clearing answer box'
        self.textbox2.Clear()
    def OnOpen(self,e):
        """ Open a file"""
        self.dirname = ''
        dlg = wx.FileDialog(self, "Choose a pack file", self.dirname, "", "*.qzp", wx.OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            self.filename=dlg.GetFilename()
            self.dirname=dlg.GetDirectory()
            f=os.path.join(self.dirname,self.filename)
            packfile(f)
        dlg.Destroy()
    def OnEdit(self, e):
    	OnNotImplemented(e)
    def OnSave(self, e):
    	OnNotImplemented(e)
    def OnPrefs(self, e):
        OnNotImplemented(e)
    def OnUpload(self, e):
        OnNotImplemented(e)
    def QuestionSet(self, text):
def guistart():
	app = wx.App()
	frame = QuizPackGUI(None, -1, 'QuizPackBETA')
	app.MainLoop()
import quizpacklib
quizpacklib.change_to_correct_path()
if __name__ == "__main__":
    guistart()
    while True:
    #Not done yet
        quizpacklib.questionnumpick()
        
        quizpacklib.evalanswer(useranswer)
        quizpacklib.totalans=quizpacklib.totalans+1
        quizpacklib.questionsans.append(quizpacklib.questionnum)
